home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / others / ole_101.zip / SCHMOO.ZIP / OLEINST.C < prev    next >
C/C++ Source or Header  |  1992-04-13  |  7KB  |  256 lines

  1. /*
  2.  * OLEINST.C
  3.  *
  4.  * OLE-Specific installation-time functions that should be performed
  5.  * once when the application is first added to the system.
  6.  *
  7.  * Note that there are embedded strings in this file.  We do not use
  8.  * strings from the application wide source in rgpsz since we want this
  9.  * module to be reusable in installation programs.
  10.  *
  11.  * Copyright(c) Microsoft Corp. 1992 All Rights Reserved
  12.  *
  13.  */
  14.  
  15. #ifdef MAKEOLESERVER
  16.  
  17. #include <windows.h>
  18. #include <shellapi.h>
  19. #include "schmoo.h"
  20. #include "oleinst.h"
  21.  
  22.  
  23. /*
  24.  * FRegDBInstall
  25.  *
  26.  * Purpose:
  27.  *  Handles any installations the applciation must handle for the
  28.  *  registration database.  In this application, we just set up to
  29.  *  call FOLEInstall that handles the OLE specific strings.
  30.  *
  31.  * Parameters:
  32.  *  None
  33.  *
  34.  * Return Value:
  35.  *  BOOL            TRUE if installation succeeded, FALSE otherwise.
  36.  *
  37.  */
  38.  
  39. BOOL FAR PASCAL FRegDBInstall(void)
  40.     {
  41.     REGINSTALL  ri;
  42.     HANDLE      hMod;
  43.     LPSTR       rgszVerbs[OBJVERB_MAX];
  44.     char        szPath[CCHPATHMAX];
  45.  
  46.     /*
  47.      * Fill the REGINSTALL structure for calling FOLEServerInstall.
  48.      * Must do this after the strings are loaded since we use strings
  49.      * from the stringtable.
  50.      */
  51.     ri.pszServerName    =(LPSTR)rgpsz[IDS_FULLNAME];
  52.     ri.pszServerClass   =(LPSTR)rgpsz[IDS_CLASSSCHMOO];
  53.     ri.pszHandlerPath   =(LPSTR)NULL;
  54.     ri.pszExt           =(LPSTR)rgpsz[IDS_DOTEXT];
  55.     ri.pszSetFormats    =(LPSTR)rgpsz[IDS_NATIVE];
  56.     ri.pszRequestFormats=(LPSTR)rgpsz[IDS_DATAFORMATS];
  57.     ri.fExecute         =FALSE;
  58.  
  59.     //Get the module path
  60.     hMod=GetModuleHandle(rgpsz[IDS_MODULE]);
  61.     GetModuleFileName(hMod, szPath, CCHPATHMAX);
  62.  
  63.     ri.pszServerPath    =(LPSTR)szPath;
  64.  
  65.     //Fill the array of pointers to verbs.
  66.     rgszVerbs[OBJVERB_EDIT]=(LPSTR)rgpsz[IDS_VERBEDIT];
  67.  
  68.     ri.ppszVerbs        =rgszVerbs;
  69.     ri.cVerbs           =OBJVERB_MAX;
  70.  
  71.     return FOLEServerInstall(&ri);
  72.     }
  73.  
  74.  
  75.  
  76.  
  77.  
  78. /*
  79.  * FOLEServerInstall
  80.  *
  81.  * Purpose:
  82.  *  Registers the server application and it's editable data types
  83.  *  with the registration database through the SHELL.DLL functions.
  84.  *
  85.  *  This function will register the server in the database if it
  86.  *  is not there already.
  87.  *
  88.  * Limitations:
  89.  *  FOLEServerInstall supports only a single class of data.
  90.  *
  91.  * Parameters:
  92.  *  pszServer       LPSTR name of the server.
  93.  *  pszData         LPSTR name of the data edited by the server.
  94.  *
  95.  * Return Value:
  96.  *  BOOL            TRUE if registration took place or the application
  97.  *                  was already registered, FALSE otherwise.
  98.  */
  99.  
  100.  
  101. BOOL FAR PASCAL FOLEServerInstall(LPREGINSTALL lpRI)
  102.     {
  103.     char        szKey[128];
  104.     char        szTemp[20];
  105.     DWORD       dw=128;
  106.     LONG        lRet;
  107.     WORD        iVerb;
  108.     LPSTR       *ppsz;
  109.  
  110.     //Check if this server is already around.
  111.     lRet=RegQueryValue(HKEY_CLASSES_ROOT, lpRI->pszServerClass, szKey, &dw);
  112.  
  113.     if ((LONG)ERROR_SUCCESS==lRet)
  114.         return TRUE;
  115.  
  116.  
  117.     /*
  118.      * Add various strings to the registration database:
  119.      *  1.  English-readable class name.
  120.      *  2.  Simple class name.
  121.      *  3.  Full path to the server executable.
  122.      *  4.  Full path to the handler DLL, if available.
  123.      *  5.  Verbs
  124.      *  6.  Any formats supported through OleSetData and OleRequestData.
  125.      *  7.  Full application path if the server supports StdExecute.
  126.      */
  127.  
  128.     //Validate essential strings
  129.     if (NULL==lpRI->pszServerClass)
  130.         return FALSE;
  131.  
  132.     if (NULL==lpRI->pszServerName)
  133.         return FALSE;
  134.  
  135.     if (NULL==lpRI->pszServerPath)
  136.         return FALSE;
  137.  
  138.     if (NULL==lpRI->pszExt)
  139.         return FALSE;
  140.  
  141.     if (NULL==lpRI->ppszVerbs || 0==lpRI->cVerbs)
  142.         return FALSE;
  143.  
  144.  
  145.     //1. English class name.  Subkey is ""
  146.     FKeyCreate(lpRI->pszServerClass, rgpsz[IDS_EMPTY], lpRI->pszServerName);
  147.  
  148.  
  149.     //2. Simple class name associated with the file extension.  Subkey is ""
  150.     FKeyCreate(lpRI->pszExt, rgpsz[IDS_EMPTY], lpRI->pszServerClass);
  151.  
  152.  
  153.     /*
  154.      * The server path, handler path, and verbs are all part of
  155.      * the \\classname\\protocol\\StdFileEditing\\ key.  Before
  156.      * creating any of the keys, create a string with the class
  157.      * name embedded.
  158.      */
  159.     wsprintf(szKey, "%s\\protocol\\StdFileEditing\\", lpRI->pszServerClass);
  160.  
  161.  
  162.     //3. Server path, append "server" onto szKey.
  163.     FKeyCreate(szKey, "server", lpRI->pszServerPath);
  164.  
  165.     //4. Add the handler path, if one exists, appening "handler" on szKey.
  166.     if (NULL!=lpRI->pszHandlerPath)
  167.         FKeyCreate(szKey, "handler", lpRI->pszHandlerPath);
  168.  
  169.     //5.  Add each verb.  Append to szKey "verb\\n" where n is a simple count.
  170.     ppsz=lpRI->ppszVerbs;
  171.  
  172.     for (iVerb=0; iVerb < lpRI->cVerbs; iVerb++)
  173.         {
  174.         //Create key and skip to next verb.
  175.         wsprintf(szTemp, "verb\\%d", iVerb);
  176.         FKeyCreate(szKey, szTemp, *ppsz++);
  177.         }
  178.  
  179.  
  180.     //6. Add the strings for formats, to "SetDataFormats" and "RequestDataFormats"
  181.     if (NULL!=lpRI->pszSetFormats)
  182.         FKeyCreate(szKey, "SetDataFormats", lpRI->pszSetFormats);
  183.  
  184.     if (NULL!=lpRI->pszSetFormats)
  185.         FKeyCreate(szKey, "RequestDataFormats", lpRI->pszRequestFormats);
  186.  
  187.  
  188.     //7. Add the StdExecute string, appending the server path.
  189.     if (lpRI->fExecute)
  190.         {
  191.         wsprintf(szKey, "%s\\protocol\\StdExecute\\", lpRI->pszServerClass);
  192.         FKeyCreate(szKey, "server", lpRI->pszServerPath);
  193.         }
  194.  
  195.     return TRUE;
  196.     }
  197.  
  198.  
  199.  
  200. /*
  201.  * FKeyCreate
  202.  *
  203.  * Purpose:
  204.  *  Short function to simplify the key creation process, centralizing
  205.  *  calls to RegCreateKey, RegSetValue, and RegCloseKey.  If the RegSetValue
  206.  *  fails, the key is deleted with RegDeleteKey.
  207.  *
  208.  * Parameters:
  209.  *  pszKey          LPSTR to keyname.
  210.  *  pszSubKey       LPSTR to last word in keyname.  This parameter is
  211.  *                  separate to enable calling RegDeleteKey on error.
  212.  *  pszValue        LPSTR to value to associate with keyname.
  213.  *
  214.  * Return Value:
  215.  *  BOOL            TRUE if registration succeeded, FALSE otherwise.
  216.  */
  217.  
  218. BOOL PASCAL FKeyCreate(LPSTR pszKey, LPSTR pszSubKey, LPSTR pszValue)
  219.     {
  220.     char        szKey[128];
  221.     HKEY        hKey;
  222.     WORD        cch;
  223.     LONG        lRet;
  224.  
  225.     cch=lstrlen(pszValue)+1;
  226.  
  227.     lstrcpy(szKey, pszKey);
  228.     lstrcat(szKey, pszSubKey);
  229.  
  230.     lRet=RegCreateKey(HKEY_CLASSES_ROOT, szKey, &hKey);
  231.  
  232.     if (lRet!=ERROR_SUCCESS)
  233.         return FALSE;
  234.  
  235.  
  236.     lRet=RegSetValue(HKEY_CLASSES_ROOT, szKey, REG_SZ, pszValue, cch);
  237.  
  238.     if (lRet!=ERROR_SUCCESS)
  239.         {
  240.         //Delete key if we could not set a value.
  241.         RegDeleteKey(hKey, pszSubKey);
  242.         return FALSE;
  243.         }
  244.  
  245.     lRet=RegCloseKey(hKey);
  246.  
  247.     if (lRet!=ERROR_SUCCESS)
  248.         return FALSE;
  249.  
  250.     return TRUE;
  251.     }
  252.  
  253.  
  254.  
  255. #endif   //MAKEOLESERVER
  256.